<!--
 * @Description: 你的代码我的心
 * @Author: GGB
 * @Date: 2021-12-21 14:39:03
 * @LastEditors: GGB
 * @LastEditTime: 2022-01-22 15:17:02
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #img="{ record }">
        <TableImg :imgList="[record.goods_image]" :size="50" />
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',
              label: '库存',
              onClick: handleEdit.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <UpdateStockModal @register="registerModal" />
  </div>
</template>
<script lang="ts" setup>
  import { BasicTable, useTable, TableAction, TableImg, FetchSetting } from '/@/components/Table';
  import { getGoodsList } from '/@/api/goods';
  import { columns, searchFormSchema } from './goods.data';
  import { UpdateStockModal } from './modal';
  import { useModal } from '/@/components/Modal';
  const [registerModal, { openModal }] = useModal();
  const [registerTable, { reload }] = useTable({
    title: '商品列表',
    api: getGoodsList,
    fetchSetting: {
      sizeField: 'pageSize',
      // // 请求接口当前页数
      pageField: 'page',
      // 请求结果列表字段  支持 a.b.c
      listField: 'list.data',
      // 请求结果总数字段  支持 a.b.c
      totalField: 'list.total',
    } as FetchSetting,
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    showIndexColumn: false,
    actionColumn: {
      width: 80,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: undefined,
    },
  });

  const handleEdit = (record: Recordable) => {
    openModal(true, { record, reload });
  };
</script>
